#include "dcmtk/config/osconfig.h"    /* make sure OS specific configuration is included first */

#include "dcmtk/dcmdata/cmdlnarg.h"
#include "dcmtk/dcmdata/dcdebug.h"
#include "dcmtk/dcmdata/dcdict.h"
#include "dcmtk/dcmdata/dcfilefo.h"
#include "dcmtk/dcmdata/dctk.h"
#include "dcmtk/dcmdata/dcuid.h"       /* for dcmtk version name */

#include "dcmtk/dcmimgle/dcmimage.h"
#include "dcmtk/dcmimgle/dicrvfit.h"
#include "dcmtk/dcmimgle/digsdfn.h"
#include "dcmtk/dcmimgle/diutils.h"

#include "dcmtk/dcmnet/dcmlayer.h"
#include "dcmtk/dcmnet/dcompat.h"     /* compatibility code, needs to be included before dirent.h */
#include "dcmtk/dcmnet/dicom.h"
#include "dcmtk/dcmnet/dimse.h"
#include "dcmtk/dcmnet/diutil.h"
#include "dcmtk/dcmnet/dul.h"

#include "dcmtk/dcmpstat/dcmpstat.h"    /* for DcmPresentationState */
#include "dcmtk/dcmpstat/dviface.h"
#include "dcmtk/dcmpstat/dvpscf.h"      /* for class DVConfiguration */
#include "dcmtk/dcmpstat/dvpscu.h"  /* for DVPSCurve */
#include "dcmtk/dcmpstat/dvpsdef.h"     /* for constants and macros */
#include "dcmtk/dcmpstat/dvpsgr.h"  /* for DVPSGraphicObject */
#include "dcmtk/dcmpstat/dvpshlp.h"
#include "dcmtk/dcmpstat/dvpsmsg.h"     /* for class DVPSIPCClient */
#include "dcmtk/dcmpstat/dvpspr.h"
#include "dcmtk/dcmpstat/dvpsprt.h"
#include "dcmtk/dcmpstat/dvpssp.h"
#include "dcmtk/dcmpstat/dvpstx.h"  /* for DVPSTextObject */

#include "dcmtk/dcmqrdb/dcmqrcnf.h"
#include "dcmtk/dcmqrdb/dcmqrdbi.h"    /* for LOCK_IMAGE_FILES */
#include "dcmtk/dcmqrdb/dcmqrdbs.h"    /* for DcmQueryRetrieveDatabaseStatus */
#include "dcmtk/dcmqrdb/dcmqropt.h"
#include "dcmtk/dcmqrdb/dcmqrsrv.h"
#ifdef WITH_SQL_DATABASE
#include "dcmtk/dcmqrdbx/dcmqrdbq.h"
#else
#include "dcmtk/dcmqrdb/dcmqrdbi.h"
#endif

#ifdef WITH_OPENSSL
#include "dcmtk/dcmtls/tlstrans.h"
#include "dcmtk/dcmtls/tlslayer.h"
#endif

#include "dcmtk/ofstd/ofbmanip.h"    /* for OFBitmanipTemplate */
#include "dcmtk/ofstd/ofcast.h"
#include "dcmtk/ofstd/ofcmdln.h"
#include "dcmtk/ofstd/ofconapp.h"
#include "dcmtk/ofstd/ofdatime.h"    /* for OFDateTime */
#include "dcmtk/ofstd/oflist.h"
#include "dcmtk/ofstd/ofstd.h"
#define INCLUDE_CCTYPE
#define INCLUDE_CERRNO
#define INCLUDE_CMATH
#define INCLUDE_CSTDARG
#define INCLUDE_CSTDIO
#define INCLUDE_CSTDLIB
#define INCLUDE_CSTRING
#define INCLUDE_CTIME
#define INCLUDE_LIBC
#include "dcmtk/ofstd/ofstdinc.h"
#include "dcmtk/ofstd/ofstream.h"
#include "dcmtk/ofstd/ofstring.h"

#ifdef HAVE_GUSI_H
/* needed for Macintosh */
#include <GUSI.h>
#include <SIOUX.h>
#endif

#ifdef WITH_ZLIB
#include <zlib.h>        /* for zlibVersion() */
#endif

#ifdef HAVE_WINDOWS_H
#include <windows.h>     /* this includes either winsock.h or winsock2.h */
#endif

BEGIN_EXTERN_C
/* This #if code is suggested by the gnu autoconf documentation */
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#define NAMLEN(dirent) strlen((dirent)->d_name)
#else
#define dirent direct
#define NAMELEN(dirent) (dirent)->d_namlen
#ifdef HAVE_SYS_NDIR_H
#include <sys/ndir.h>
#endif
#ifdef HAVE_SYS_DIR_H
#include <sys/dir.h>
#endif
#ifdef HAVE_NDIR_H
#include <ndir.h>
#endif
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>      /* for O_RDONLY */
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>   /* required for sys/stat.h */
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>    /* for stat, fstat */
#endif
#ifdef HAVE_SYS_FILE_H
#include <sys/file.h>
#endif
#ifdef HAVE_SYS_WAIT_H
#include <sys/wait.h>
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#ifdef HAVE_SYS_RESOURCE_H
#include <sys/resource.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#ifdef HAVE_SYS_ERRNO_H
#include <sys/errno.h>
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
END_EXTERN_C

extern "C" T_DIMSE_BlockingMode             opt_blockMode;
extern "C" int             opt_dimse_timeout;
extern "C" int             opt_acse_timeout;
extern "C" OFCmdUnsignedInt   opt_sleepAfter;
extern "C" OFCmdUnsignedInt   opt_sleepDuring;
extern "C" OFCmdUnsignedInt   opt_maxPDU;
extern "C" OFBool             opt_useMetaheader;
extern "C" E_TransferSyntax   opt_networkTransferSyntax;
extern "C" E_TransferSyntax   opt_writeTransferSyntax;
extern "C" E_GrpLenEncoding   opt_groupLength;
extern "C" E_EncodingType     opt_sequenceType;
extern "C" E_PaddingEncoding  opt_paddingType;
extern "C" OFCmdUnsignedInt   opt_filepad;
extern "C" OFCmdUnsignedInt   opt_itempad;
extern "C" OFBool             opt_verbose;
extern "C" OFBool            opt_debug;
extern "C" OFBool            opt_bitPreserving;
extern "C" OFBool            opt_ignore;
extern "C" OFBool            opt_abortDuringStore;
extern "C" OFBool            opt_abortAfterStore;
extern "C" OFBool            opt_correctUIDPadding;
extern "C" ostream *        logstream;
extern "C" DVPSIPCClient *messageClient;
extern "C" OFCmdUnsignedInt opt_port;

void closeLog();
void errmsg(const char* msg, ...);
void print(OFList<int>& l);